package com.example.demoproject.fragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.demoproject.R;

public class DynamicFragment2 extends Fragment {
    private IFragmentCallBack callBack;
    private View root;
    private String msgFromActivity;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("lfy","[DynamicFragment2] onCreate...callBack="+callBack);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (root == null){
            root = inflater.inflate(R.layout.fragment_dynamic_fragment2,container,false);
        }
        Log.d("lfy","[DynamicFragment2] onClick...111...callBack="+callBack);
        Button btn = root.findViewById(R.id.fragmentBtn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TextView dyText2 = root.findViewById(R.id.dyText2);
                dyText2.setText(msgFromActivity);
            }
        });

        return root;
    }

    public void setCallBack(IFragmentCallBack callBack){
        Log.d("lfy","[DynamicFragment2] setCallBack...callBack="+callBack);
        callBack = callBack;
        msgFromActivity = callBack.getMsgFromActivity();
        Log.d("lfy","[DynamicFragment2] setCallBack...msgFromActivity="+msgFromActivity);
    }
}
